﻿<UserControl x:Class="SoGame.Views.NewPlayerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:me="clr-namespace:SoGame.ViewModels" 
             mc:Ignorable="d" 
             KeyDown="NewPlayerView_KeyDown"
             d:DesignHeight="600" d:DesignWidth="800" Width="Auto">
    <UserControl.Resources>
        <me:NewPlayerViewModel x:Key="viewModel" />
        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
        	<WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
        </ItemsPanelTemplate>

    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" KeyDown="NewPlayerView_KeyDown" DataContext="{Binding Source={StaticResource viewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.6*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="0.3*"/>
        </Grid.ColumnDefinitions>
        <ListBox ItemsSource="{Binding Players}" 
                 SelectedItem="{Binding CurrentPlayer, Mode=TwoWay}" 
                 ScrollViewer.VerticalScrollBarVisibility="Visible" Grid.RowSpan="5" Margin="0,0,10,0" BorderBrush="{x:Null}" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}">
        	<ListBox.Resources>
        		<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
        			<Setter Property="Background" Value="Transparent"/>
        			<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        			<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        			<Setter Property="Padding" Value="2,0,0,0"/>
        			<Setter Property="Template">
        				<Setter.Value>
        					<ControlTemplate TargetType="{x:Type ListBoxItem}">
        						<Grid Height="Auto">
        							<VisualStateManager.VisualStateGroups>
        								<VisualStateGroup x:Name="CommonStates">
        									<VisualState x:Name="Normal"/>
        									<VisualState x:Name="MouseOver">
        										<Storyboard>
        											<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
        												<EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
        											</DoubleAnimationUsingKeyFrames>
        										</Storyboard>
        									</VisualState>
        									<VisualState x:Name="Disabled"/>
        								</VisualStateGroup>
        								<VisualStateGroup x:Name="SelectionStates">
        									<VisualState x:Name="Unselected"/>
        									<VisualState x:Name="Selected">
        										<Storyboard>
        											<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
        												<EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
        											</DoubleAnimationUsingKeyFrames>
        										</Storyboard>
        									</VisualState>
        									<VisualState x:Name="SelectedUnfocused"/>
        								</VisualStateGroup>
        								<VisualStateGroup x:Name="FocusStates">
        									<VisualState x:Name="Unfocused"/>
        									<VisualState x:Name="Focused">
        										<Storyboard>
        											<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="rectangle">
        												<EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
        											</DoubleAnimationUsingKeyFrames>
        										</Storyboard>
        									</VisualState>
        								</VisualStateGroup>
        								<VisualStateGroup x:Name="ValidationStates">
        									<VisualState x:Name="Valid"/>
        									<VisualState x:Name="InvalidFocused"/>
        									<VisualState x:Name="InvalidUnfocused"/>
        								</VisualStateGroup>
        							</VisualStateManager.VisualStateGroups>
        							<Rectangle x:Name="rectangle" HorizontalAlignment="Stretch" Stroke="{x:Null}" Fill="{DynamicResource MetroMenuItemHover}" Opacity="0"/>
        							<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true" d:LayoutOverrides="Width, Height">
        								<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="12,6"/>
        							</Border>
        						</Grid>
        						<ControlTemplate.Triggers>
        							<Trigger Property="IsSelected" Value="true">
        								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
        							</Trigger>
        							<MultiTrigger>
        								<MultiTrigger.Conditions>
        									<Condition Property="IsSelected" Value="true"/>
        									<Condition Property="Selector.IsSelectionActive" Value="false"/>
        								</MultiTrigger.Conditions>
        								<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        							</MultiTrigger>
        							<Trigger Property="IsEnabled" Value="false">
        								<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        							</Trigger>
        						</ControlTemplate.Triggers>
        					</ControlTemplate>
        				</Setter.Value>
        			</Setter>
        		</Style>
        	</ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                    	<Grid.ColumnDefinitions>
                    		<ColumnDefinition Width="Auto"/>
                    		<ColumnDefinition Width="*"/>
                    	</Grid.ColumnDefinitions>
                		<StackPanel d:LayoutOverrides="Width, Height" Grid.ColumnSpan="1" Grid.Column="1" Margin="12,-5,0,0" Grid.RowSpan="2">
                			<StackPanel Orientation="Horizontal">
                				<TextBlock Text="{Binding Name}" Style="{DynamicResource ItemTitle}"/>
                				<TextBlock Text="{Binding FirstName}" Style="{DynamicResource ItemTitle}" Margin="5,0,0,0"/>
                			</StackPanel>
							<TextBlock Text="{Binding GamePlays.Count, StringFormat=\{0\} partie(s)}" Style="{DynamicResource MetroNormalText}" Foreground="{DynamicResource HighlightBrush}"/>
                			<TextBlock Text="{Binding Email}" Foreground="{DynamicResource LabelTextBrush}" VerticalAlignment="Top" Margin="0,0,-52,0" Style="{DynamicResource ItemDescription}"/>
                		</StackPanel>
                		<Grid Height="50" VerticalAlignment="Center" Width="50">
                			<Rectangle Grid.Column="0" Fill="{DynamicResource HighlightBrush}" HorizontalAlignment="Left" Stroke="{x:Null}" Width="50" Height="Auto" VerticalAlignment="Stretch"/>
                			<Image Source="{Binding Photo}" HorizontalAlignment="Stretch" Height="Auto" Width="Auto" VerticalAlignment="Stretch"/>
                		</Grid>
                	</Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Grid x:Name="Infos" Grid.Column="2" Grid.RowSpan="5" Margin="0,0,0,-50">
        	<Grid.RowDefinitions>
        		<RowDefinition Height="Auto"/>
        		<RowDefinition Height="Auto"/>
        		<RowDefinition Height="*"/>
        	</Grid.RowDefinitions>
        	<StackPanel x:Name="NewPanel" Visibility="{Binding ElementName=LayoutRoot, Path=DataContext.IsEditMode, Converter={StaticResource VisibilityConverter}, ConverterParameter='false'}"  Orientation="Horizontal" d:LayoutOverrides="Width, GridBox">
        		<Image Width="30" Source="/SoGame;component/Assets/Images/add.png" Height="30"/>
        		<TextBlock TextWrapping="Wrap" d:LayoutOverrides="Height" Text="nouveau joueur" VerticalAlignment="Center" Margin="5,-15,0,0" FontSize="42.667" FontFamily="Segoe UI Light" Style="{DynamicResource MetroHeader}"/>
        	</StackPanel>
        	<StackPanel x:Name="EditPanel" Visibility="{Binding ElementName=LayoutRoot, Path=DataContext.IsEditMode, Converter={StaticResource VisibilityConverter}}" Orientation="Horizontal" d:LayoutOverrides="Width, GridBox">
        		<Image Height="30" Width="30" Source="/SoGame;component/Assets/Images/edit.png"/>
        		<TextBlock TextWrapping="Wrap" d:LayoutOverrides="Height" Text="édition joueur" VerticalAlignment="Center" Margin="5,-15,0,0" FontSize="42.667" FontFamily="Segoe UI Light" Style="{DynamicResource MetroHeader}"/>
        	</StackPanel>
        	<Grid Grid.Row="1" d:LayoutOverrides="GridBox" VerticalAlignment="Top">
        		<Grid.ColumnDefinitions>
        			<ColumnDefinition Width="Auto"/>
        			<ColumnDefinition Width="*"/>     	
        		</Grid.ColumnDefinitions>
        		<Grid>
        			<Grid.RowDefinitions>
        				<RowDefinition Height="*"/>
        				<RowDefinition Height="Auto"/>
        			</Grid.RowDefinitions>
                    <Grid Height="300" Visibility="{Binding CanDisplayKinectSource}">
                    	<Image Source="{Binding KinectSource}" d:LayoutOverrides="GridBox, VerticalMargin"/>
        				<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Height="38" VerticalAlignment="Top">
        					<Button Content="UP" Click="Button_Click" VerticalAlignment="Bottom"/>
        					<Button Content="DOWN" Click="Button_Click_1" VerticalAlignment="Bottom"/>
        				</StackPanel>
        			</Grid>
        			<Grid Visibility="{Binding CanDisplayNormalSource}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="100" Background="{DynamicResource GrayBrush8}">
        				<Image Source="{Binding CurrentPlayer.Photo}" HorizontalAlignment="Center" VerticalAlignment="Center" Width="62" Height="62" />
        			</Grid>
        			<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center" Margin="0,12">
        				<Button Visibility="{Binding CanDisplayNormalSource}" Command="{Binding DataContext.CaptureCommand, ElementName=LayoutRoot}" VerticalAlignment="Bottom">
        					<StackPanel Orientation="Horizontal">
        						<Image Source="/SoGame;component/Assets/Images/basic-icon-camera.png" HorizontalAlignment="Center" VerticalAlignment="Center" Width="26" Height="26"/>
        						<TextBlock Text="Prendre une photo" VerticalAlignment="Center" Margin="6,0"/>                 	
        					</StackPanel>                  
        				</Button>
						<Button Visibility="{Binding CanDisplayKinectSource}" Command="{Binding DataContext.TakePictureCommand, ElementName=LayoutRoot}" VerticalAlignment="Bottom">
        					<StackPanel Orientation="Horizontal">
        						<Image Source="/SoGame;component/Assets/Images/basic-icon-camera.png" HorizontalAlignment="Center" VerticalAlignment="Center" Width="26" Height="26"/>
        						<TextBlock Text="Prendre la photo" VerticalAlignment="Center" Margin="6,0"/>                 	
        					</StackPanel>                  
        				</Button>
        			</StackPanel>
        		</Grid>
        		<Grid Grid.Column="1" Margin="15,0,0,0">
        			<Grid.RowDefinitions>
        				<RowDefinition Height="Auto"/>
        				<RowDefinition Height="Auto"/>
        				<RowDefinition Height="Auto"/>
        				<RowDefinition Height="Auto"/>
        				<RowDefinition Height="*"/>
        			</Grid.RowDefinitions>
        			<Grid.ColumnDefinitions>
        				<ColumnDefinition Width="Auto"/>
        				<ColumnDefinition Width="*"/>
        			</Grid.ColumnDefinitions>
        			<TextBlock TextWrapping="Wrap" Foreground="Black" Text="Nom :" FontSize="18.667" Style="{DynamicResource HeaderTextStyle}" Margin="0,0,5,0"/>
        			<TextBlock TextWrapping="Wrap" Foreground="Black" Text="Prénom :" FontSize="18.667" Grid.Row="1" Margin="0,5,5,0" Style="{DynamicResource HeaderTextStyle}"/>
        			<TextBlock TextWrapping="Wrap" Foreground="Black" Text="E-mail :" FontSize="18.667" Grid.Row="2" Margin="0,5,5,10" Style="{DynamicResource HeaderTextStyle}"/>
        			<TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" TextWrapping="Wrap" Foreground="Black" FontSize="18.667" Grid.Column="1"/>
        			<TextBox TextWrapping="Wrap" Foreground="Black" Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" FontSize="18.667" Grid.Row="1" Grid.Column="1" Margin="0,5,0,0"/>
        			<TextBox TextWrapping="Wrap" Foreground="Black" Text="{Binding Email, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True}" FontSize="18.667" Grid.Row="2" Grid.Column="1" Margin="0,5,0,10"/>
        			<CheckBox Grid.Row="3" IsChecked="{Binding AuthorizePhotoUsage, Mode=TwoWay}" Content="Autoriser la publication de la photo sur la page FaceBook So@tExperts" VerticalAlignment="Center" Grid.ColumnSpan="2" VerticalContentAlignment="Center"/>
        			<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" Grid.Row="4" Grid.ColumnSpan="2" Margin="0,12,0,0">
        				<Button Content="Enregistrer" Command="{Binding SaveCommand}" HorizontalAlignment="Center"/>
        				<Button Content="Annuler" Command="{Binding CancelCommand}" HorizontalAlignment="Center" Margin="5,0,0,0"/>
        			</StackPanel>
        		</Grid>
        	</Grid>
        	<Grid Grid.Row="2" Visibility="{Binding ElementName=LayoutRoot, Path=DataContext.IsEditMode, Converter={StaticResource VisibilityConverter}}" >
        		<Grid.RowDefinitions>
        			<RowDefinition Height="Auto"/>
        			<RowDefinition Height="*"/>
        		</Grid.RowDefinitions>
        		<TextBlock TextWrapping="Wrap" Text="parties" d:LayoutOverrides="Width, Height" Style="{DynamicResource MetroHeaderBold}"/>
        		<ListBox ItemsSource="{Binding CurrentPlayer.GamePlays}" 
                         SelectedItem="{Binding CurrentGamePlay, Mode=TwoWay}"
                         ItemsPanel="{DynamicResource ItemsPanelTemplate1}" 
                         Grid.Row="1">
        	<!--<ListBox.ItemPanel>
        		<WrapPanel Orientation="Horizontal"/>     	
			</ListBox.ItemPanel>-->
        			<ListBox.ItemTemplate>
        				<DataTemplate>
        					<StackPanel Height="Auto" Width="Auto">
        						<Grid Margin="0" Height="99" Width="99">
        							<Rectangle Fill="{DynamicResource HighlightBrush}" Width="173" Height="173" d:LayoutOverrides="VerticalMargin"/>
                                    <Image Source="{Binding Photo}" VerticalAlignment="Stretch"/>
									<Button Margin="5" Command="{Binding ElementName=LayoutRoot, Path=DataContext.ShowPhoto}" HorizontalAlignment="Right" VerticalAlignment="Bottom">
										<Image Margin="-10" Source="/SoGame;component/Assets/Images/appbar.feature.search.rest_thumb_5F51CF6F.png" Width="30"/>
									</Button>
                                </Grid>
        						<StackPanel Margin="0" d:LayoutOverrides="HorizontalAlignment">
        							<TextBlock Text="{Binding Date, StringFormat=dd/MM/yy HH:mm}" Style="{DynamicResource ItemDate}"/>
        							<TextBlock Text="{Binding Game}" Style="{DynamicResource ItemTitle}"/>
        							<TextBlock Text="{Binding Score, StringFormat=Score: \{0\}}" Style="{DynamicResource ItemDescription}" Margin="0" Foreground="{DynamicResource HighlightBrush}" FontSize="16"/>			
        						</StackPanel>    		
        					</StackPanel>    		
        				</DataTemplate>     	
        			</ListBox.ItemTemplate>      
        		</ListBox>
        	</Grid>
        </Grid>
        <Image Source="/SoGame;component/Assets/Images/AVATAR.png" HorizontalAlignment="Right" Grid.RowSpan="4" Grid.Column="5" Grid.Row="1"/>
    </Grid>
</UserControl>
